<?php

namespace app\speedDating\controller\member;

use app\speedDating\AppController;
use app\speedDating\services\common\UploadService;
use app\speedDating\web\JsonResult;

class UtilsController extends AppController
{
    public function upload(UploadService $service)
    {
        $data['file'] = request()->file('file');
        $data['upload_config_id'] = request()->param('upload_config_id',1);
        $data['rename'] = request()->param('rename');
        $data['edit'] = request()->param('edit', 1);

        $this->validate(
            $data,
            [
                'file' => 'require|file',
                'rename' => 'require',
            ],
            [
                'file.require' => '上传资源不能为空',
                'file.file' => '上传资源必须为文件',
                'rename.require' => '文件名不能为空',
            ]
        );

        $urlData = $service->upload($data);
        $result['url'] = $urlData;
        if (is_array($urlData)){
            $result['url'] = '';
            $result['oss'] = $urlData;
        }

        return JsonResult::success($result);
    }

}